#include <stdio.h>
#include <string.h>
#include <sys/stat.h>  
 
unsigned long get_file_size(const char *path)  //获取文件大小
{    
	unsigned long filesize = -1;
	struct stat statbuff;

    if(stat(path, &statbuff) < 0)
    {
        return filesize;    
    }
    else
    {
        filesize = statbuff.st_size;
    }

	return filesize;
}

int main(int argc, char *argv[])
{
    char buffer[50];
    char* s = "runoobcom";
    // unsigned long filesize = get_file_size(argv[1]); //文件大小
    // printf("filesize = %ld 字节\r\n",filesize);
 
    // 读取字符串并存储在 buffer 中
    int j = snprintf(buffer, 16, "%s\n", s);
 
    // 输出 buffer及字符数
    printf("string:\n%s\ncharacter count = %d\n", buffer, j);

    /* 读取并显示数据 */
    FILE* fp = fopen(argv[1], "rb+");//打开要上传的图片
    int readbyte = fread(buffer, 1, 4, fp);
    printf("readbyte = %d 字节\r\n",readbyte);
    printf("%s\n", buffer);
 
    return 0;
}